var LevelPause = {
    _util: new Util(),
    _manage: null,
    _refer: null,
    _pauseLayer: null,
    mIsPlayingAnim: false,
    _preventDefault: true,
    _musicBtn: null,
    init: function(){
        this._util.onAssignCCBMemberVariable(this.assignActive());
        var layerNode = this._util.newLayerFromCCB(s_pauseRing_ccbi, this._refer);
        this._pauseLayer = layerNode;
        this._manage = this._util.ccbReader.getAnimationManager();
        this._manage.setCompletedAnimationCallback(this, this.onCCBAnimEnd);
        
        if (layerNode != null) {
            this._refer.addChild(layerNode, 4);
        }
        
    },
    onEnter: function(refer){
        cc.log("onEnter")
        this._refer = refer;
        this._refer.pauseLevelPlay();
        this.mIsPlayingAnim = true;
        this.init();
        this._pauseLayer.setVisible(true);
        this._manage.runAnimations("In");
        this.outAction = null;
    },
    onResume: function(){
        cc.log("onResume")
        if (!this.mIsPlayingAnim) {
            this._manage.runAnimations("Out");
            //            this.mIsPlayingAnim = true;
            this.outAction = function(){
                this._refer.resumeLevel();
                this._refer.setState(LevelPlay);
            }
        }
    },
    onExit: function(){
        cc.log("onExit")
        this._pauseLayer.setVisible(false);
    },
    onMainmenu: function(){
        var $this = this;
        this._manage.runAnimations("Out");
        this.mIsPlayingAnim = true;
        var layer = SelectLevelLayer.create();
        this.outAction = function(){
            //reset level layer to normal shader
            //ngccxUtils: GetInstance(): resetNodeGray(level.getBaseLayer(), true)	C++ 函数
            $this._refer.exitLevel();
            game.enterSelectLevels();
        }
    },
    onRetry: function(){
        var $this = this;
        this._manage.runAnimations("Out");
        this.mIsPlayingAnim = true;
        this.outAction = function(){
            $this._refer.resumeLevel();
            $this._refer.retryLevel();
        }
    },
    assignActive: function(){
        var arr = new Array();
        var $this = this;
        this._musicBtn = {
            key: "btnMusic",
            callback: function(){
                sound.playButtonSound();
                $this._preventDefault = false;
                game.switchSoundOnOff();
                game.updateSoundButton(this);
            }
        }
        arr.push({
            key: "btnRetry",
            callback: function(){
                sound.playButtonSound();
                $this._preventDefault = false;
                $this.onRetry();
            }
        });
        arr.push(this._musicBtn);
        arr.push({
            key: "btnMainMenu",
            callback: function(){
                sound.playButtonSound();
                $this._preventDefault = false;
                $this.onMainmenu();
            }
        });
        return arr;
    },
    isPlayingAnim: function(){
        return this.mIsPlayingAnim;
    },
    outAction: null,
    onCCBAnimEnd: function(){
        this.mIsPlayingAnim = false;
        var animName = this._manage.getLastCompletedSequenceName();
        if (animName == "Out") {
            if (this.outAction != null) {
                this.outAction();
            }
        } else if (animName == "In") {
            game.updateSoundButton(this._musicBtn.instance);
        }
    },
    onTouch: function(event){
        if (this._pauseLayer && this._pauseLayer.isVisible() && this._preventDefault) {
            this.onResume();
        }
        this._preventDefault = true;
    }
}
